package com.jshx.sz.gdjt.thread;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONObject;

import com.jshx.sz.gdjt.thread.data.DataProUtil;
import com.jshx.sz.gdjt.util.AccessDBImp;
import com.jshx.sz.gdjt.util.TDESEncodeUtils;
import com.jshx.sz.gdjt.util.file.UploadItem;
import com.jshx.sz.gdjt.util.file.UploadMultiFileThread;
import com.jshx.sz.gdjt.constant.ApplicationGlobal;
import com.jshx.sz.gdjt.db.DataBaseUtil;

import android.content.pm.PackageInfo;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
 
/**
 * 登录验证通过以后同步数据
 * @author YP
 * @time 2013-08-30
 */
public class LoginDataSynchronizedThread  extends Thread{
	private Handler handler;
	public LoginDataSynchronizedThread()
	{
		
	}
	
 	public LoginDataSynchronizedThread(Handler handler)
	{
		this.handler=handler;
	}
	public void run() 
	{
		try {
			 
			//1.同步互检人信息-----------开始
			//删除
			DataBaseUtil dao=new DataBaseUtil();
			dao.deleteCheckUser();
			this.synPerson();//增加
			//1.同步互检人信息-----------结束
			
		 
			
			
			Message msg=new Message();
			msg.what=ApplicationGlobal.data_obtained;
			handler.sendMessage(msg) ;
		} catch (Exception e) {
			System.out.println(e);
			e.printStackTrace();
			Message msg=new Message();
			msg.what=ApplicationGlobal.data_missed;
			handler.sendMessage(msg) ;
		}  
	}
	  
	
	/**
	 * 同步互检人
	 * @throws Exception 
	 */
	private void synPerson() throws Exception
	{
		AccessDBImp dao= new AccessDBImp();
		String re=dao.proDB("getPersonList", ",'userId':'" + ApplicationGlobal.userId + "','type':'getPersonList'");
		ArrayList list  =dao.splitDataList(re);
		for(int i=0;i<list.size();i++ )
		{
			HashMap<String,String> map =(HashMap<String,String>) list.get(i);
			HashMap<String, String> reMap=new HashMap<String, String>();
			reMap.put("user_id", map.get("EMPLOYEE_ID"));
			reMap.put("user_name", map.get("EMPLOYEE_NAME"));
			reMap.put("team_id", map.get("DEPT_ID"));
			DataBaseUtil.insertCheckUserData(reMap);
		}
	} 
	
	
	private Handler handler1 = new Handler() {        
		@Override
        public void handleMessage(Message msg) {
	}};
}
